package com.javasm.service.impl;

import com.alibaba.fastjson.JSON;
import com.javasm.dao.AdminMenuDao;
import com.javasm.dao.AdminUserDao;
import com.javasm.entity.AdminMenu;
import com.javasm.entity.AdminUser;
import com.javasm.service.LoginService;
import com.javasm.utils.MyBatisHeapler;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @version 0.1
 * @className: LoginServiceImpl
 * @description:
 * @author: gfs
 * @date: 2025/6/19 15:57
 * @since: jdk17
 */
public class LoginServiceImpl implements LoginService {
    @Override
    public AdminUser getUserByName(String username) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        AdminUserDao mapper = sqlSession.getMapper(AdminUserDao.class);
        AdminUser loginUser = mapper.getUserByName(username);
        MyBatisHeapler.backSqlSession(sqlSession);
        return loginUser;
    }

    @Override
    public void updateUserLoginTime(Long uid) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        AdminUserDao mapper = sqlSession.getMapper(AdminUserDao.class);
        mapper.updateUserLoginTime(9l);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
    }

    @Override
    public List<AdminMenu> listMenuByUid(Long uid) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        AdminMenuDao mapper = sqlSession.getMapper(AdminMenuDao.class);
        List<AdminMenu> adminMenus = mapper.listMenuByUid(uid);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return adminMenus;
    }

    @Override
    public List<String> listUserUrl(Long uid) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        AdminUserDao mapper = sqlSession.getMapper(AdminUserDao.class);
        List<String> listUrl = mapper.listUserUrl(uid);
        System.out.println(listUrl);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return listUrl;
    }
}
